/*
 * CPLEXProblemSolver.h
 *
 *  Created on: 28/apr/2013
 *      Author: Ialenti Andrea, Marangon Fabio
 */

#ifndef CPLEXPROBLEMSOLVER_H_
#define CPLEXPROBLEMSOLVER_H_

#include "StatusCodes.h"
#include "Types.h"

//	Find sub-tour elimination constraint from the current CPLEX solution.
int findSECs(const Config *cfg, CPXENVptr env, CPXLPptr lp, const Problem *p, SEC *secs, int *totSECs, bool cb, cbData *myData, void *cbdata, int from, bool verbose);

//	Function used to find a cycle in a CPLEX solution.
Status visitCycle(const Config *cfg, int **adjMat, int nodes, int *cLengths, int *nCycles, int *cycles);

//	Solve the TSP problem iteratively adding SEC constraints.
Status solveIterMiliotis(const Config *cfg, CPXENVptr env, CPXLPptr lp, const Problem *p, const Graph *g, bool verbose, bool ps, time_t t1);

//	This function is used to run the "proximity search" method to find heuristic tours quickly.
Status proxySearch(const Config *cfg, CPXENVptr env, CPXLPptr lp, CPXLPptr psLP, Problem *p, const Problem *psP, Graph *g, bool verbose);

//	This function is used to update the proximity search constraint and the objective function.
Status changePSconstr(const Config *cfg, CPXENVptr env, CPXLPptr psLP, const Problem *p, const Graph *g, double *x, double theta);

//	This function is used to add the SECs coming from the lagrangian 1-tree.
Status addLagrangianSECs(const Config *cfg, CPXENVptr env, CPXLPptr lp, const Problem *p, OneTree *lagrTree);

//	This function is used to extract SECs from a 1-tree.
Status extractSECsFromOneTree(const Config *cfg, CPXENVptr *env, CPXLPptr *lp, const OneTree *t, SEC *secs, const Problem *p, int *actualTree, int *alreadyRoot, int *howManySECs);

//	This function is used to build and add the SEC.
Status buildSEC(const Config *cfg, CPXENVptr *env, CPXLPptr *lp, int *nodes, const Problem *p, SEC *secs, int *howManySECs);

//	Function called to know the nodes of the subtree of OneTree t, with root-node "root"
void visitSubtree(const OneTree *t, int root, int *actualNodeNumber, int father, int *actualTree, int *alreadyRoot);

#endif /* CPLEXPROBLEMSOLVER_H_ */
